package com.wx.demo.mvc.action;

import com.wx.demo.service.IDemoService;
import com.wx.mvcframework.annotation.Autowired;
import com.wx.mvcframework.annotation.Controller;
import com.wx.mvcframework.annotation.RequestMapping;
import com.wx.mvcframework.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/demo")
public class DemoAction {

  	@Autowired
	private IDemoService demoService;


	@RequestMapping("/query")
	public void query(HttpServletRequest req, HttpServletResponse resp,
			   @RequestParam("name") String name){
		String result = demoService.get(name);
//		String result = "My name is " + name;
		try {
			resp.getWriter().write(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@RequestMapping("/add")
	public void add(HttpServletRequest req, HttpServletResponse resp,
                    @RequestParam("a") Integer a, @RequestParam("b") Integer b){
		try {
			resp.getWriter().write(a + "+" + b + "=" + (a + b));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@RequestMapping("/remove")
	public void remove(HttpServletRequest req,HttpServletResponse resp,
					   @RequestParam("id") Integer id){
	}

}
